﻿namespace IBTrader.Indicator.CandleStick
{
    using IBTrader.Charts;

    /// <summary>
    /// Chaikin Money Flow measures the amount of Money Flow Volume over a specific period. 
    /// Money Flow Volume forms the basis for the Accumulation Distribution Line. 
    /// The resulting indicator fluctuates above/below the zero line just like an oscillator. 
    /// </summary>
    class CMF : BaseVolume
    {
        private readonly Prices volumes;
        public CMF(Worker worker, int interval = 60, int pinterval = 20) : base(worker, 1, interval, pinterval) { volumes = new Prices(pinterval); }
        protected override void Add(object _, Item item)
        {
            Prices.Add(ADL.Calc(item));
            volumes.Add(item.Volume);
            OnHit(item.CloseLine, NaN(Prices.Sum / volumes.Sum));
        }
    }
}
